package managedbean;

import entity.AddressEntity;
import entity.BranchEntity;
import entity.FnBBranchEntity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import javax.faces.model.SelectItem;
import util.enumeration.CuisineType;
import util.enumeration.FnbType;
import util.enumeration.OperatingHours;



@ManagedBean
@ViewScoped

public class AddNewBranchManagedBean implements Serializable
{
    private BranchEntity branch;
    private List<CuisineType> cuisineTypes;
    
    private SelectItem[] cuisineTypeSelectItems;
    private SelectItem[] fnbTypeSelectItems;
    private SelectItem[] operatingHoursSelectItems;
    private SelectItem[] isHalalSelectItems;
    private SelectItem[] priceRangeSelectItems;
    
    private OperatingHours mondayStart;
    
    
    
    public AddNewBranchManagedBean()
    {        
    }
    
    
    
    public void initView(PhaseEvent event)
    {
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        
        if(branch == null)
        {
            branch = new BranchEntity();
            branch.setBranchAddress(new AddressEntity());
            branch.setFnBBranch(new FnBBranchEntity());
            
            this.cuisineTypes = new ArrayList<CuisineType>();
            
            
            
            CuisineType[] cuisineTypes = CuisineType.values();
            cuisineTypeSelectItems = new SelectItem[cuisineTypes.length];

            for(int i = 0; i < cuisineTypes.length; i++)
            {
                cuisineTypeSelectItems[i] = new SelectItem(cuisineTypes[i], cuisineTypes[i].toString());
            }
            
            
            FnbType[] fnbTypes = FnbType.values();
            fnbTypeSelectItems = new SelectItem[fnbTypes.length];

            for(int i = 0; i < fnbTypes.length; i++)
            {
                fnbTypeSelectItems[i] = new SelectItem(fnbTypes[i], fnbTypes[i].toString());
            }
            
            
            OperatingHours[] operatingHours = OperatingHours.values();
            operatingHoursSelectItems = new SelectItem[operatingHours.length];
            
            for(int i = 0; i < operatingHours.length; i++)
            {
                operatingHoursSelectItems[i] = new SelectItem(operatingHours[i], operatingHours[i].toString());
            }
            
            isHalalSelectItems = new SelectItem[2];
            isHalalSelectItems[0] = new SelectItem("Yes", "Yes");
            isHalalSelectItems[1] = new SelectItem("No", "No");
            
            priceRangeSelectItems = new SelectItem[7];
            priceRangeSelectItems[0] = new SelectItem("SELECT", "SELECT");
            priceRangeSelectItems[1] = new SelectItem("Less Than $20", "Less Than $20");
            priceRangeSelectItems[2] = new SelectItem("$21 - $40", "$21 - $40");
            priceRangeSelectItems[3] = new SelectItem("$41 - $60", "$41 - $60");
            priceRangeSelectItems[4] = new SelectItem("$61 - $80", "$61 - $80");
            priceRangeSelectItems[5] = new SelectItem("$81 - $100", "$81 - $100");
            priceRangeSelectItems[6] = new SelectItem("More Than $100", "More Than $100");
        }
    }
    
    
    
    public void saveNewBranch(ActionEvent event)
    {
        System.out.println("********** addNewBranchManagedBean.saveNewBranch: branch.branchName: " + branch.getBranchName());
        System.out.println("********** addNewBranchManagedBean.saveNewBranch: branch.Address.buildingName: " + branch.getBranchAddress().getBuildingName());
        
        for(CuisineType cuisineType : cuisineTypes)
        {
            System.out.println("********** addNewBranchManagedBean.saveNewBranch: cuisineTypes: " + cuisineType);
        }
        
        System.out.println("********** addNewBranchManagedBean.saveNewBranch: branch.fnBBranch.fnBTypeEnumId: " + branch.getFnBBranch().getFnBTypeEnum());
        System.out.println("********** addNewBranchManagedBean.saveNewBranch: branch.fnBBranch.priceRange: " + branch.getFnBBranch().getPriceRange());
        System.out.println("********** addNewBranchManagedBean.saveNewBranch: branch.fnBBranch.isHalal: " + branch.getFnBBranch().getIsHalal());
        
        System.out.println("********** addNewBranchManagedBean.saveNewBranch: mondayStart: " + mondayStart);
    }
    
    
    
    public SelectItem[] getCuisineTypeSelectItems()
    {               
        return cuisineTypeSelectItems;
    }
    
    
    
    public SelectItem[] getFnbTypeSelectItems()
    {                
        return fnbTypeSelectItems;
    }
    
    
    
    public SelectItem[] getOperatingHoursSelectItems()
    {                
        return operatingHoursSelectItems;
    }
    
    
    
    public SelectItem[] getIsHalalSelectItems()
    {                
        return isHalalSelectItems;
    }
    
    
    
    public SelectItem[] getPriceRangeSelectItems()
    {                
        return priceRangeSelectItems;
    }

    
    
    public BranchEntity getBranch() {
        return branch;
    }

    public void setBranch(BranchEntity branch) {
        this.branch = branch;
    }

    public List<CuisineType> getCuisineTypes() {
        return cuisineTypes;
    }

    public void setCuisineTypes(List<CuisineType> cuisineTypes) {
        this.cuisineTypes = cuisineTypes;
    }

    public OperatingHours getMondayStart() {
        return mondayStart;
    }

    public void setMondayStart(OperatingHours mondayStart) {
        this.mondayStart = mondayStart;
    }    
}
